<template>
  <el-dialog
    top="1vh"
    :close-on-click-modal="false"
    append-to-body
    :title="title"
    :visible.sync="dialogVisible"
    width="80%"
    @closed="handleClose"
    v-loading="loading">

    <div style="max-height: 600px;overflow-x: hidden; margin-right: -20px">
      <div style="padding-right: 20px">
        <a-form ref="form" :data="data" :definition="definition" :span="6" :rules="rules">

          <!-- 房产信息 -->
          <template v-slot:house>
            <div v-for="(item,index) in house">
              <a-form :key="index" :data="item" :definition="houseDefinition" :span="6">
                <template v-slot:delete>
                  <el-button
                    v-if="!(formType === 3 || formType === 4)"
                    style="width: 100px"
                    type="primary"
                    plain
                    icon="el-icon-delete"
                    size="mini"
                    @click="house.splice(index,1)"/>
                </template>
              </a-form>
            </div>
            <el-button
              v-if="!(formType === 3 || formType === 4)"
              style="width: 100px"
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="house.push({})">
              新增房产
            </el-button>
          </template>

          <!-- 车产信息 -->
          <template v-slot:car>
            <div v-for="(item,index) in car">
              <a-form :key="index" :data="item" :definition="carDefinition" :span="5">
                <template v-slot:delete>
                  <el-button
                    v-if="!(formType === 3 || formType === 4)"
                    style="width: 100px"
                    type="primary"
                    plain
                    icon="el-icon-delete"
                    size="mini"
                    @click="car.splice(index,1)"/>

                </template>
              </a-form>
            </div>
            <el-button
              v-if="!(formType === 3 || formType === 4)"
              style="width: 100px"
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="car.push({})">
              新增车产
            </el-button>
          </template>

          <!-- 保险信息 -->
          <template v-slot:insurance>
            <div v-for="(item,index) in insurance">
              <a-form :key="index" :data="item" :definition="insuranceDefinition" :span="5">
                <template v-slot:delete>
                  <el-button
                    v-if="!(formType === 3 || formType === 4)"
                    style="width: 100px"
                    type="primary"
                    plain
                    icon="el-icon-delete"
                    size="mini"
                    @click="insurance.splice(index,1)"/>
                </template>
              </a-form>
            </div>
            <el-button v-if="!(formType === 3 || formType === 4)"
                       style="width: 100px"
                       type="primary"
                       plain
                       icon="el-icon-plus"
                       size="mini"
                       @click="insurance.push({})">
              新增保单
            </el-button>
          </template>

          <!-- 需求表格 -->
          <template v-slot:needTable>
            <div style="text-align: right; padding-top: 10px; padding-bottom: 20px;">
              <el-button v-if="!(formType === 3 || formType === 4)"
                         style="width: 120px" type="primary" plain icon="el-icon-check" size="mini" @click="needSave">
                保存
              </el-button>
              <el-button v-if="!(formType === 3 || formType === 4)" v-has-permi="['addRequirement']"
                         style="width: 120px" type="primary" plain icon="el-icon-plus" size="mini" @click="needAdd">
                添加需求
              </el-button>
            </div>
            <a-table v-model="needTableData" :table-config="needDefinition"/>
          </template>

          <!-- 分配记录表格 -->
          <template v-slot:allocationTable>
            <a-table v-loading="allocationLoading" v-model="allocationData" :table-config="allocationDefinition"/>
            <div style="text-align: center; padding-top: 10px; padding-bottom: 20px;">
              <el-button style="width: 120px" type="primary" plain icon="el-icon-refresh" size="mini"
                         @click="selectAllocationList(id,null)">
                刷新
              </el-button>
              <el-button :disabled="allocationDisabled" style="width: 120px" type="primary" icon="el-icon-circle-plus"
                         plain
                         size="mini" @click="selectAllocationList(id,allocationData[allocationData.length-1].id,true)">
                {{ allocationDisabled ? '没有更多了' : '展示更多' }}
              </el-button>
            </div>
          </template>

          <!-- 编辑客户信息记录表格 -->
          <template v-slot:snapshotTable>
            <a-table v-loading="snapshotLoading" v-model="snapshotData" :table-config="snapshotDefinition"/>
            <div style="text-align: center; padding-top: 10px; padding-bottom: 20px;">
              <el-button style="width: 120px" type="primary" plain icon="el-icon-refresh" size="mini"
                         @click="selectSnapshotList(id,null)">
                刷新
              </el-button>
              <el-button :disabled="snapshotDisabled" style="width: 120px" type="primary" icon="el-icon-circle-plus"
                         plain
                         size="mini" @click="selectSnapshotList(id,snapshotData[snapshotData.length-1].id,true)">
                {{ snapshotDisabled ? '没有更多了' : '展示更多' }}
              </el-button>
            </div>
          </template>

        </a-form>

      </div>
    </div>


    <span slot="footer" class="dialog-footer">
      <el-button @click="cancel" v-loading="loading">取 消</el-button>
      <el-button v-if="this.formType !== 3" type="primary" @click="submit" v-loading="loading">确 定</el-button>
    </span>

    <snapshot ref="snapshot"/>

  </el-dialog>
</template>

<script>
import {
  addInfo,
  addNeed,
  allocationList,
  backCustomerSnapshot,
  deleteNeed,
  getCustomerSnapshot,
  getInfo,
  needList,
  snapshotList,
  updateInfo
} from "@/api/lion/customerInfo";
import ATable from "@/components/FlyElement/aTable.vue";
import snapshot from "@/views/loan/common/snapshot.vue";

export default {
  name: "MyForm",
  components: {ATable, snapshot},
  computed: {
    title: {
      get() {
        switch (this.formType) {
          case 1:
            return '新增客户'
          case 2:
            return '编辑客户'
          case 3:
            return '查看客户'
          case 4:
            return '编辑记录'
        }
      }
    }
  },
  data() {
    return {
      loading: false,
      // 页面类型 1新增 2编辑 3明细 4客户信息快照
      formType: 1,
      dialogVisible: false,
      data: {},
      rules: {
        name: [
          {required: true, message: "客户姓名不能为空", trigger: "blur"},
        ],
        phoneNumber: [
          {required: true, message: "手机号码不能为空", trigger: "blur"},
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "手机号码格式错误",
            trigger: "blur"
          }
        ],
        idCard: [
          {
            pattern: /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|[xX])$/,
            message: "身份证号错误",
            trigger: "blur"
          }
        ],
        age: [
          { max: 3, message: '年龄大小不合理', trigger: 'blur' }
        ]
      },
      definition: [
        {
          type: 'divider',
          label: '基本信息',
          span: 24
        },
        {
          prop: 'phoneNumber',
          label: '手机号码',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'name',
          label: '姓名',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          label: "",
          span: 12,
          type: 'slot'
        },
        {
          prop: "sex",
          label: "性别",
          type: 'radio',
          option: [
            {key: 0, label: '男'},
            {key: 1, label: '女'}
          ],
          disabled: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'age',
          label: '年龄',
          itemType: 'number',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'city',
          label: '申请城市',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'maritalStatus',
          label: '婚姻',
          type: 'radio',
          option: [
            {key: 1, label: '已婚'},
            {key: 0, label: '未婚'}
          ],
          disabled: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'birthday',
          label: '生日',
          type: 'datePicker',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'spouseSpouse',
          label: '配偶生日',
          type: 'datePicker',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'weddingAnniversary',
          label: '结婚纪念日',
          type: 'datePicker',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          label: "",
          span: 6,
          type: 'slot'
        },
        {
          prop: 'idCard',
          label: '身份证',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'spouseIdCard',
          label: '配偶身份证',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'level',
          label: '客户星级',
          type: 'select',
          dict: 'customer_level',
          disabled: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'status',
          label: '客户状态',
          type: 'select',
          dict: 'customer_status',
          disabled: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'remark',
          label: '备注',
          itemType: 'textarea',
          span: 12,
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'expense',
          label: '费用',
          itemType: 'textarea',
          span: 12,
          readonly: () => this.formType === 3 || this.formType === 4,
          hasPer: ['expense']
        },
        {
          type: 'divider',
          label: '需求信息',
          span: 24
        },
        {
          prop: 'amount',
          label: '金额(万)',
          itemType: 'number',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'loanUse',
          label: '贷款用途',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'loanRemark',
          label: "备注",
          span: 12,
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'timeLimit',
          label: '期数',
          itemType: 'number',
          min: 1,
          step: 1,
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'serviceTime',
          label: '用款时间',
          type: 'datePicker',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'lendingInstitution',
          label: '放款机构',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          label: "",
          span: 6,
          type: 'slot'
        },
        {
          prop: 'repaymentType',
          label: '还款方式',
          type: 'radio',
          option: [
            {key: 1, label: '月'},
            {key: 2, label: '季度'}
          ],
          disabled: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'repaymentMonth',
          label: '还款月',
          type: 'select',
          if: () => this.data.repaymentType === 2,
          option: [
            {key: 1, label: '第一月'},
            {key: 2, label: '第二月'},
            {key: 3, label: '第三月'}
          ],
          disabled: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'repaymentDay',
          label: '还款日',
          type: 'select',
          option: [
            {key: 1, label: '第1日'},
            {key: 2, label: '第2日'},
            {key: 3, label: '第3日'},
            {key: 4, label: '第4日'},
            {key: 5, label: '第5日'},
            {key: 6, label: '第6日'},
            {key: 7, label: '第7日'},
            {key: 8, label: '第8日'},
            {key: 9, label: '第9日'},
            {key: 10, label: '第10日'},
            {key: 11, label: '第11日'},
            {key: 12, label: '第12日'},
            {key: 13, label: '第13日'},
            {key: 14, label: '第14日'},
            {key: 15, label: '第15日'},
            {key: 16, label: '第16日'},
            {key: 17, label: '第17日'},
            {key: 18, label: '第18日'},
            {key: 19, label: '第19日'},
            {key: 20, label: '第20日'},
            {key: 21, label: '第21日'},
            {key: 22, label: '第22日'},
            {key: 23, label: '第23日'},
            {key: 24, label: '第24日'},
            {key: 25, label: '第25日'},
            {key: 26, label: '第26日'},
            {key: 27, label: '第27日'},
            {key: 28, label: '第28日'},
            {key: 29, label: '第29日'},
            {key: 30, label: '第30日'},
            {key: 31, label: '第31日'}
          ],
          disabled: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'repaymentAmount',
          label: '还款金额',
          itemType: 'number',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'deadline',
          label: '截止日期',
          type: 'datePicker',
          placeholder: '配置自动生成',
          disabled: true,
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'needTable',
          labelWidth: '0px',
          label: '',
          span: 24,
          type: 'slot',
          if: () => this.id !== undefined && this.id !== null && this.id !== ''
        },
        {
          type: 'divider',
          label: '身份信息',
          span: 24
        },
        {
          prop: 'occupation',
          label: '职位',
          type: 'radio',
          dict: 'customer_occupation',
          span: 24,
          disabled: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'occupationRemark',
          label: '职位备注',
          itemType: 'textarea',
          span: 12,
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          type: 'divider',
          label: '房产信息',
          span: 24
        },
        {
          labelWidth: '60px',
          label: '',
          prop: 'house',
          type: 'slot',
          span: 24
        },
        {
          type: 'divider',
          label: '车产信息',
          span: 24
        },
        {
          labelWidth: '60px',
          label: '',
          prop: 'car',
          type: 'slot',
          span: 24
        },
        {
          type: 'divider',
          label: '保单信息',
          span: 24
        },
        {
          labelWidth: '60px',
          label: '',
          prop: 'insurance',
          type: 'slot',
          span: 24
        },
        {
          type: 'divider',
          label: '分配记录',
          span: 24,
          if: () =>  this.formType === 3
        },
        {
          labelWidth: '60px',
          label: '',
          prop: 'allocationTable',
          type: 'slot',
          span: 24,
          if: () =>  this.formType === 3
        },
        {
          type: 'divider',
          label: '编辑客户信息记录',
          span: 24,
          if: () =>  this.formType === 3
        },
        {
          labelWidth: '60px',
          label: '',
          prop: 'snapshotTable',
          type: 'slot',
          span: 24,
          if: () =>  this.formType === 3
        }
      ],
      // 房产
      houseDefinition: [
        {
          labelWidth: '60px',
          prop: 'cellName',
          label: '小区名',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          labelWidth: '60px',
          prop: 'area',
          label: '面积',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          labelWidth: '120px',
          prop: 'price',
          label: '预估现价(万)',
          itemType: 'number',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          labelWidth: '10px',
          label: "",
          type: 'slot',
          prop: 'delete',
          readonly: () => this.formType === 3 || this.formType === 4
        }
      ],
      house: [],
      // 车产
      carDefinition: [
        {
          labelWidth: '50px',
          prop: 'brand',
          label: '品牌',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          labelWidth: '50px',
          prop: 'modelNumber',
          label: '型号',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          labelWidth: '90px',
          prop: 'year',
          label: '购车年份',
          type: 'datePicker',
          format: 'yyyy',
          itemType: 'year',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          labelWidth: '120px',
          span: 6,
          prop: 'price',
          label: '预估现价(万)',
          itemType: 'number',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          labelWidth: '10px',
          span: 3,
          label: "",
          type: 'slot',
          prop: 'delete',
          readonly: () => this.formType === 3 || this.formType === 4
        }
      ],
      car: [],
      // 保单
      insuranceDefinition: [
        {
          prop: 'company',
          label: '保险公司',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'amount',
          label: '年缴金额',
          itemType: 'number',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          prop: 'year',
          label: '购买年份',
          type: 'datePicker',
          format: 'yyyy',
          itemType: 'year',
          readonly: () => this.formType === 3 || this.formType === 4
        },
        {
          labelWidth: '10px',
          label: "",
          type: 'slot',
          prop: 'delete'
        }
      ],
      insurance: [],
      // id
      id: undefined,
      // 客户需求table
      needTableData: [],
      // 客户需求表单定义
      needDefinition: [
        {
          prop: 'amount',
          label: '申请金额（万）'
        },
        {
          prop: 'loanUse',
          label: '贷款用途'
        },
        {
          prop: 'timeLimit',
          label: '期数'
        },
        {
          width: '120px',
          prop: 'serviceTime',
          label: '用款时间'
        },
        {
          prop: 'lendingInstitution',
          label: '放款机构'
        },
        {
          prop: 'repaymentType',
          label: '还款方式',
          formatter(data) {
            if (data === '1'){
              return '月'
            }
            return '季度'
          }
        },
        {
          prop: 'repaymentMonth',
          label: '还款月',
          formatter(data, index, item) {
            if (item.repaymentType === "2") {
              switch (data) {
                case "1":
                  return '第一月'
                case "2":
                  return '第二月'
                case "3":
                  return '第三月'
              }
            }
            return ''
          }
        },
        {
          width: '120px',
          prop: 'repaymentDay',
          label: '还款日',
          formatter(data) {
            return `第${data}日`
          }
        },
        {
          prop: 'repaymentAmount',
          label: '还款金额'
        },
        {
          width: '120px',
          prop: 'deadline',
          label: '截止日期'
        },
        {
          prop: 'loanRemark',
          label: '备注'
        },
        {
          width: '150px',
          prop: 'createTime',
          label: '创建时间'
        },
        {
          width: 100,
          fixed: 'right',
          handle: [
            {
              template: 'delete',
              hasPer: ['deleteDemandInfo'],
              handle: (data) => {
                this.deleteNeed(data)
              }
            }
          ]
        }
      ],
      allocationDefinition: [
        {
          prop: 'id',
          label: '记录编号'
        },
        {
          prop: 'remark',
          label: '分配记录'
        },
        {
          prop: 'createTime',
          label: '分配时间'
        },
        {
          prop: 'operatorName',
          label: '操作人'
        }
      ],
      allocationData: [],
      allocationLoading: true,
      allocationDisabled: false,
      // 编辑记录
      snapshotDefinition: [
        {
          prop: 'id',
          label: '记录编号'
        },
        {
          prop: 'createTime',
          label: '编辑时间'
        },
        {
          prop: 'nickName',
          label: '操作人'
        },
        {
          handle: [
            {
              icon: 'el-icon-view',
              text: '查看',
              handle: (data) => {
                this.getCustomerSnapshot(data)
              }
            },
            {
              icon: 'el-icon-back',
              text: '回滚',
              hasPer: ['rollback'],
              handle: (data) => {
                this.backCustomerSnapshot(data)
              }
            }
          ]
        }
      ],
      snapshotData: [],
      snapshotLoading: true,
      snapshotDisabled: false,
      queryRequest:{id: undefined, custId: undefined}
    }
  },
  methods: {
    open(formType, id) {
      this.id = id
      this.formType = formType
      if (id) {
        this.selectData(id)
        this.selectNeedList(id)
        this.selectAllocationList(id, null)
        this.selectSnapshotList(id, null)
      }
      this.dialogVisible = true
    },

    selectData(id) {
      getInfo(id).then(response => {
        this.data = response.data
        this.house = this.arrayJsonParse(this.data.houseJson)
        this.car = this.arrayJsonParse(this.data.carJson)
        this.insurance = this.arrayJsonParse(this.data.insuranceJson)
      })
    },

    selectNeedList(customerInfoId) {
      needList({customerInfoId}).then(response => {
        this.needTableData = response.data
      })
    },

    selectAllocationList(customerInfoId, id, add = false) {
      this.allocationLoading = true
      allocationList({customerInfoId, id}).then(response => {
        if (add) {
          response.data.forEach(item => this.allocationData.push(item))
        } else {
          this.allocationData = response.data
        }
        this.allocationDisabled = response.data.length < 5
        this.allocationLoading = false
      })
    },

    selectSnapshotList(customerInfoId, id, add = false) {
      this.snapshotLoading = true
      snapshotList({customerInfoId, id}).then(response => {
        if (add) {
          response.data.forEach(item => this.snapshotData.push(item))
        } else {
          this.snapshotData = response.data
        }
        this.snapshotDisabled = response.data.length < 5
        this.snapshotLoading = false
      })
    },

    handleClose() {
      this.data = {}
      this.house = []
      this.car = []
      this.insurance = []
      this.dialogVisible = false

      this.$refs.form.clearValidate()
    },

    submit() {
      const validate = this.$refs.form.validate();
      if (!validate) {
        return
      }

      this.loading = true
      this.data.houseJson = JSON.stringify(this.house)
      this.data.carJson = JSON.stringify(this.car)
      this.data.insuranceJson = JSON.stringify(this.insurance)
      if (this.id) {
        updateInfo(this.data).then(() => {
          this.$message({message: '编辑客户成功', type: 'success'})
          this.$emit('getList')
          this.dialogVisible = false
          this.loading = false
        })
      } else {
        addInfo(this.data).then(() => {
          this.$message({message: '添加客户成功', type: 'success'})
          this.$emit('getList')
          this.dialogVisible = false
          this.loading = false
        })
      }
    },

    cancel() {
      this.dialogVisible = false
    },

    arrayJsonParse(jsonStr) {
      if (jsonStr === null || jsonStr === undefined || jsonStr === '') {
        return []
      }
      return JSON.parse(jsonStr)
    },

    // 保存需求
    needSave() {
      const data = {
        id: this.data.id,
        amount: this.data.amount,
        loanUse: this.data.loanUse,
        loanRemark: this.data.loanRemark,
        timeLimit: this.data.timeLimit,
        serviceTime: this.data.serviceTime,
        lendingInstitution: this.data.lendingInstitution,
        repaymentType: this.data.repaymentType,
        repaymentMonth: this.data.repaymentMonth,
        repaymentDay: this.data.repaymentDay,
        repaymentAmount: this.data.repaymentAmount,
        deadline: this.data.deadline
      }
      updateInfo(data).then(() => {
        this.$message({message: '保存需求成功', type: 'success'})
        this.$emit('getList')
      })
    },

    // 添加需求
    needAdd() {
      if (this.errorMessage(this.data.amount, "金额")) {
        return
      }
      if (this.errorMessage(this.data.loanUse, "贷款用途")) {
        return
      }
      if (this.errorMessage(this.data.timeLimit, "期数")) {
        return
      }
      if (this.errorMessage(this.data.serviceTime, "用款时间")) {
        return
      }
      if (this.errorMessage(this.data.lendingInstitution, "放款机构")) {
        return
      }
      if (this.errorMessage(this.data.repaymentType, "还款方式")) {
        return
      }
      if (this.data.repaymentType === '2') {
        if (this.errorMessage(this.data.repaymentMonth, "还款月")) {
          return
        }
      }
      if (this.errorMessage(this.data.repaymentDay, "还款日")) {
        return
      }
      if (this.errorMessage(this.data.repaymentAmount, "还款金额")) {
        return
      }

      const data = {
        customerInfoId: this.data.id,
        amount: this.data.amount,
        loanUse: this.data.loanUse,
        loanRemark: this.data.loanRemark,
        timeLimit: this.data.timeLimit,
        serviceTime: this.data.serviceTime,
        lendingInstitution: this.data.lendingInstitution,
        repaymentType: this.data.repaymentType,
        repaymentMonth: this.data.repaymentMonth,
        repaymentDay: this.data.repaymentDay,
        repaymentAmount: this.data.repaymentAmount,
        deadline: this.data.deadline
      }
      addNeed(data).then(() => {
        this.selectData(this.id)
        this.selectNeedList(this.id)
        this.$message({message: '添加客户需求成功', type: 'success'})
        this.$emit('getList')
      })
    },

    errorMessage(data, message) {
      if (data === null || data === undefined || data === '') {
        this.$message.error(message + '不能为空');
        return true
      }
      return false
    },

    // 删除需求
    deleteNeed(data) {
      deleteNeed(data.id).then(() => {
        this.selectData(this.id)
        this.selectNeedList(this.id)
        this.$message({message: '删除客户需求成功', type: 'success'})
        this.$emit('getList')
      })
    },

    getCustomerSnapshot(data) {
      getCustomerSnapshot(data.id).then(res => {
        this.$refs.snapshot.open(res)
      })

    },

    backCustomerSnapshot(data) {
      this.queryRequest.id = data.id
      this.queryRequest.custId = this.id
      backCustomerSnapshot(this.queryRequest).then(res => {
        this.selectData(this.id)
        this.selectSnapshotList(this.id, null)
        this.$message({message: '回滚客户快照成功', type: 'success'})
      })
    }

  }
}
</script>

<style scoped>

</style>
